//
//  BanBu_magicWordsCell.m
//  Koochat
//
//  Created by 张毅飞 on 14-9-23.
//
//

#import "BanBu_magicWordsCell.h"

@implementation BanBu_magicWordsCell
{
    UIWebView * _webview;
    CGFloat _webViewHeight;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
-(void)dealloc
{
    [_webview release];
    _webview =nil;
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _webview=[[UIWebView alloc]initWithFrame:CGRectMake(self.sayTextLabel.frame.origin.x,self.sayTextLabel.frame.origin.y+5, 235, 60)];
        _webview.delegate=self;
        _webview.scrollView.bounces=NO;
        _webview.scrollView.scrollEnabled=NO;
        [self.shadowView addSubview:_webview];
        self.sayTextLabel.hidden=YES;
        self.backgroundColor=[UIColor clearColor];
    }
    return self;
}
-(void)setWebviewWithDic:(NSDictionary *)dictionary
{
    NSString * htmlStr=[dictionary valueForKey:@"saytext"];
    NSData * data=[NSData dataFromBase64String:htmlStr];
    NSString * hhh=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    [_webview loadHTMLString:hhh baseURL:nil];
    [hhh release];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    /*
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    
    CGSize fittingSize=[webView sizeThatFits:CGSizeZero];
    if (fittingSize.height>60) {
        fittingSize=CGSizeMake(235, 60);
        webView.scrollView.scrollEnabled=NO;
    }
    
    frame.size=fittingSize;
    webView.frame=frame;
    */
    //国外webView内存泄露解决办法，不知道真的假的
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];//自己添加的，原文没有提到。
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];//自己添加的，原文没有提到。
    [[NSUserDefaults standardUserDefaults] synchronize];

}

-(CGFloat)getWebviewHeight
{
    return _webViewHeight;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
